package main

import (
	"flag"
	"fmt"
	"testing"
)

var input = flag.Int("num", 12, "get input")

func fibonacci(c, quit chan int) {
	x, y := 1, 1
	for {
		select {
		case c <- x:
			x, y = y, x+y
		case <-quit:
			// fmt.Println("quit")
			return
		}
	}
}

func singleFab(num int) {

	c := make(chan int)
	quit := make(chan int)

	go func() {
		for i := 0; i < num; i++ {
			<-c
		}
		quit <- 0
	}()
	fibonacci(c, quit)

}

// func BenchmarkFunction(n int, b *testing.B) {
// 	for i := 0; i < b.N; i++ {
// 		singleFab(n)
// 	}
// }

func BenchmarkFunction(n int) func(b *testing.B) {
	return func(b *testing.B) {
		for i := 0; i < b.N; i++ {
			singleFab(n)
		}
	}
}

type BenchmarkFunctionPtr func(b *testing.B)

// var arr []BenchmarkFunctionPtr

func main() {
	flag.Parse()
	// arr := make([]BenchmarkFunctionPtr, *input)
	for index := 0; index < *input; index++ {
		// arr[index] = test(index)
		br := testing.Benchmark(BenchmarkFunction(index))
		fmt.Println("BenchmarkFunction", index+1, br)
	}
}
